/**
	Copyright (c) 2010 ATTi 
	All rights reserved.
	Author: Michael Shu
	Date: 2/19/2010
*/
@isTest
private class LeadSharkPoolTriggerTester {
	private static Integer NUM = 10;
	private static String SFA_Office_Missing = 'SFA office missing';    
	private static Map<String, List<String>> QueueNameSFAs = new Map<String, List<String>>{
		               'SFA Las Vegas Lead Sharkpool Queue'   => new List<String>{'Las Vegas'}, 
	                   'SFA Los Angeles Lead Sharkpool Queue' => new List<String>{'Dallas','Los Angeles'},
	                   'SFA Miami Lead Sharkpool Queue'       => new List<String>{'Detriot','Jacksonville-MFL','Miami','Orlando'},
	                   'SFA Philly Lead Sharkpool Queue'      => new List<String>{'Philadelphia'},
	                   'SFA Salt Lake Lead Sharkpool Queue'   => new List<String>{'Salt Lake City'},
	                   'SFA Office field missing Lead Queue'  => new List<String>{SFA_Office_Missing}};	
	private static Map<String, String> sfa_office_queues = new Map<String, String>{
		               'Las Vegas' => 'SFA Las Vegas Lead Sharkpool Queue',
		               'Dallas' => 'SFA Los Angeles Lead Sharkpool Queue',
		               'Los Angeles' => 'SFA Los Angeles Lead Sharkpool Queue',
		               'Detriot' => 'SFA Miami Lead Sharkpool Queue',
		               'Jacksonville-MFL' => 'SFA Miami Lead Sharkpool Queue',
		               'Miami' => 'SFA Miami Lead Sharkpool Queue',
		               'Orlando' => 'SFA Miami Lead Sharkpool Queue',
		               'Philadelphia' => 'SFA Philly Lead Sharkpool Queue',
		               'Salt Lake City' => 'SFA Salt Lake Lead Sharkpool Queue',
		               '' => SFA_Office_Missing};
	private static  List<String> sfa_office_names = new List<String>{'Las Vegas', 'Dallas', 'Los Angeles', 'Detriot', 'Jacksonville-MFL'
		                                                           , 'Miami','Orlando', 'Philadelphia', 'Salt Lake City', ''};
		               
	private static Set<String> ExLeadSourceNames = new Set<String>{'Prospect', 'Salesgenie.com'};                 
	                              
	private static ID leadLocalAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeID('Lead', 'Local Advertiser');	
    private static Profile[] Profiles = [select Id from Profile where Name like '%SFA%'];	
    private static Group[] SharkpoolQueues = [select Id, Name from Group where Type = 'Queue' and Name IN: QueueNameSFAs.keySet()];
    private static Group AnyQueue = [select Id, Name from Group where Type = 'Queue' and Name = 'Market Groups Queue' limit 1];
    private static Map<String, ID> queueNameIds = new Map<String, ID>();
    /*
    public static testMethod void testLeadSharkPoolQueue() {
    	Integer i;	
    	
    	List<User> users = new List<User>();
    	for(i = 0; i < NUM; i++){
    		User u = new User(LastName = 'Test Lead Shark Pool Queue'+i);
    		u.UserName = 'Test_login_in@test.com'+i;
    		u.Email = 'test@att.com';
    		u.CommunityNickname = 'Test' + i;
    		u.TimeZoneSidKey = 'America/Los_Angeles';
    		u.LocaleSidKey = 'en_US';
    		u.EmailEncodingKey = 'UTF-8';
    		Integer index_profile = math.mod(i, Profiles.size());
    		u.ProfileId = Profiles[index_profile].Id;
    		u.LanguageLocaleKey = 'en_US';
    		u.Alias = 'sfa_test';
    		Integer index_sfa_office = math.mod(i, sfa_office_names.size());
    		u.SFA_Office__c = sfa_office_names[index_sfa_office];
    		users.add(u);
    	}
    	insert users;
    	
    	User[] u_rst = [select Id from User u where u.LastName like 'Test Lead Shark Pool Queue%'];
    	System.assertEquals(NUM, u_rst.size());
    	
    	List<Lead> leads = new List<Lead>();
    	for(i = 0; i < NUM; i++){
	    	Lead l = new Lead(RecordTypeId = leadLocalAdvertiserRecordTypeID, Company = 'Test Lead Shark Pool Company' + i);
	    	Integer index_user = math.mod(i, u_rst.size());
	    	l.OwnerId = u_rst[index_user].Id;
	    	l.Zip_Postal_Code__c = '90898';
	    	l.LastName = 'sfa_test' + i;
	    	if(i == 0){
	    		l.LeadSource = 'Call In';
	    		l.Status = 'No Sale - Do Not Call';    		
	    	}else if(i == 1){
	    		l.LeadSource = 'Call In';
	    		l.Status = 'No Sale - Do Not Call';  	    	
	    	}else if(i == 2){
	    		l.LeadSource = 'Prospect';
	    		l.Status = 'Duplicate';  	    		
	    	}else if(i == 3){
	    		l.PostalCode = '90898';
	    		l.LeadSource = 'Salesgenie.com';
	    		l.Status = 'Duplicate';  	    		
	    	}else{
		    	l.LeadSource = 'Direct Mail';
		    	l.Status = 'Open';
	    	} 
	    	leads.add(l);
    	}
        insert leads;
    	Map<ID, Lead> l_rst_step1 = new Map<ID, Lead>([select Id, Is7DaysEnabled__c, Latest_Owner_Change_Date__c, LeadSource, Status  
    	                                               from Lead l where l.Company like 'Test Lead Shark Pool Company%']);
    	System.assertEquals(NUM, leads.size());
    	for(Lead l : l_rst_step1.values()){
    		if(l.LeadSource != 'Salesgenie.com' && l.LeadSource != 'Prospect' && l.Status != 'No Sale - Do Not Call'){
    			System.assertEquals(true, l.Is7DaysEnabled__c, 'l.LeadSource = ' + l.LeadSource + ' ; l.Status = ' + l.Status);
    		}
    	}
    	Clock__c[] clocks = [Select c.isClockEnabled__c, c.IsTimeOut__c, c.Latest_Owner_Change_Date__c , c.Lead__c from Clock__c c where Lead__c IN : l_rst_step1.keySet()]; 
    	System.assertEquals((NUM - 4), clocks.size());
    	i = 0;
    	for(Clock__c c : clocks){
    		System.assertEquals(true, c.isClockEnabled__c);
    		System.assertEquals(false, c.IsTimeOut__c);
    		System.assertEquals(l_rst_step1.get(c.Lead__c).Latest_Owner_Change_Date__c , c.Latest_Owner_Change_Date__c, ' i = ' + i);
    		i++;
    	}
    	
    	for(lead l : l_rst_step1.values()){
    		if(l.LeadSource == 'Salesgenie.com' || l.LeadSource == 'Prospect'){
    			l.LeadSource = 'Call In';
    		}
    		if(l.Status == 'No Sale - Do Not Call'){
    			l.Status = 'Duplicate';
    		}
    	}
    	
    	System.assertEquals(false, LeadSharkpoolClass.getIsFirstBefore());
    	System.assertEquals(false, LeadSharkpoolClass.getIsFirstAfter());
    	LeadSharkpoolClass.setIsFirstBefore(true);
    	LeadSharkpoolClass.setIsFirstAfter(true);    	
    	update l_rst_step1.values();
    	    	
    	Map<ID, Lead> l_rst_step2 = new Map<ID, Lead>([select Id, Is7DaysEnabled__c, Latest_Owner_Change_Date__c, LeadSource, Status, IsOver7Days__c 
    	                                               from Lead l where l.Company like 'Test Lead Shark Pool Company%']);
    	for(Lead l : l_rst_step2.values()){
    		System.assertEquals(true, l.Is7DaysEnabled__c, 'l.LeadSource = ' + l.LeadSource + ' ; l.Status = ' + l.Status);
    	}
    	
    	Clock__c[] clocks_step2 = [Select c.isClockEnabled__c, c.IsTimeOut__c, c.Latest_Owner_Change_Date__c, c.Lead__c from Clock__c c where Lead__c IN : l_rst_step1.keySet()];
    	
     	System.assertEquals(NUM , clocks_step2.size());
    	for(Clock__c c : clocks_step2){
    		System.assertEquals(true, c.isClockEnabled__c);
    		System.assertEquals(false, c.IsTimeOut__c);
    		System.assertEquals(l_rst_step2.get(c.Lead__c).Latest_Owner_Change_Date__c , c.Latest_Owner_Change_Date__c);
    		c.IsTimeOut__c = true;
    	}   	 
    	
    	System.assertEquals(false, LeadSharkpoolClass.getIsFirstBefore());
    	System.assertEquals(false, LeadSharkpoolClass.getIsFirstAfter());
    	    	
    	LeadSharkpoolClass.setIsFirstBefore(true);
    	LeadSharkpoolClass.setIsFirstAfter(true);   	
    	update clocks_step2;
    	
    	Map<ID, Lead> l_rst_step3 = new Map<ID, Lead>([select Id, Latest_Owner_Change_Date__c  from Lead l where l.Company like 'Test Lead Shark Pool Company%']);
    	Clock__c[] clocks_step3 = [Select c.isClockEnabled__c, c.IsTimeOut__c, c.Latest_Owner_Change_Date__c, c.Lead__c from Clock__c c where Lead__c IN : l_rst_step1.keySet()];
    	System.assertEquals(0 , clocks_step3.size());
    	
    }

    public static testMethod void testLeadSharkPoolQueueforLeadQueueOwner() {
    	Integer i;
     	List<Lead> leads = new List<Lead>();
    	for(i = 0; i < NUM; i++){
	    	Lead l = new Lead(RecordTypeId = leadLocalAdvertiserRecordTypeID, Company = 'Test Lead Shark Pool with Queue Owner' + i);
	    	l.OwnerId = AnyQueue.Id;
	    	l.Zip_Postal_Code__c = '90898';
	    	l.LastName = 'sfa_test' + i; 	    		
	    	l.LeadSource = 'Direct Mail';
	    	l.Status = 'Open';
	    	leads.add(l);
    	}
        insert leads;
    	Map<ID, Lead> l_rst_step1 = new Map<ID, Lead>([select Id, Is7DaysEnabled__c, Latest_Owner_Change_Date__c, LeadSource, Status  
    	                                               from Lead l where l.Company like 'Test Lead Shark Pool with Queue Owner%']);
    	System.assertEquals(NUM, leads.size()); 
    	for(Lead l : l_rst_step1.values()){
    		System.assertEquals(false, l.Is7DaysEnabled__c, 'l.LeadSource = ' + l.LeadSource + ' ; l.Status = ' + l.Status);
    	}
    	Clock__c[] clocks = [Select c.isClockEnabled__c, c.IsTimeOut__c, c.Latest_Owner_Change_Date__c , c.Lead__c from Clock__c c where Lead__c IN : l_rst_step1.keySet()]; 
    	System.assertEquals(0, clocks.size());  	
    }*/	
}